package com.demo.crm.springboot3security.entity;

import java.time.LocalDateTime;
import java.util.List;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.RelationOneToMany;
import com.mybatisflex.annotation.Table;

import lombok.Data;

/**
 * 功能模块实体
 */
@Data
@Table("modules")
public class Module {
    @Id
    private Long id;

    @Column
    private String name; // 模块名称

    @Column
    private String code; // 模块编码

    private String description; // 模块描述

    @Column
    private String icon; // 模块图标

    @Column
    private Integer orderNum; // 排序号

    @Column("parent_id")
    private Long parentId; // 父模块ID

    @Column
    private String layoutConfig; // 布局配置（JSON格式）

    @RelationOneToMany(selfField = "id", targetField = "module_id")
    private List<CustomForm> forms; // 关联的表单

    private boolean enabled; // 是否启用

    @Column
    private LocalDateTime createdAt;

    @Column
    private LocalDateTime updatedAt;

    public void prePersist() {
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }

    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
}